<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Users
 *
 * @author Samuel Pulta
 */
class Users extends Jobfair {

    //put your code here

    //public $unique_id;
    public $username;
    public $password;
    public $profile_id;
    public $account_type;
    public $date_created;
    public $date_modified;
    public $status;
    public $status_1;
    public $email;
    public $email_activated;
    public $is_active;

    public function __construct($db, $id) {
        $this->init($db, $id);
    }

    public function init($db, $id) {
        $this->db = $db;
        $this->tblname = "tb_users";
        
        if ($id) {
            $result = $this->db->query("SELECT * FROM {$this->tblname} WHERE id = {$this->db->escape($id)}", "row");
            
            $this->id = $result['id'];
            //$this->unique_id = $result['unique_id'];
            $this->username = $result['username'];
            $this->password = $result['password'];
            $this->profile_id = $result['profile_id'];
            $this->account_type = $result['account_type'];
            $this->date_created = $result['date_created'];
            $this->date_modified = $result['date_modified'];
            $this->status = $result['status'];
            $this->status_1 = $result['status_1'];
            $this->email = $result['email'];
            $this->email_activated = $result['email_activated'];
            $this->is_active = $result['is_active'];
            
        }
    }
    
    public function query_all($condition){
        
        if($condition != ""){
            $con = " WHERE " . $condition . " AND ";
        }else{
            $con = " WHERE ";
        }
            $result = $this->db->query("SELECT * FROM {$this->tblname} $con is_active={$this->db->escape(1)}", "array");
            
            return $result;
    }   

    public function save() {
        $insert_array = array(
            //"unique_id"         =>    $this->unique_id,
            "username"          =>    $this->username,
            "password"          =>    $this->password,
            "profile_id"        =>    $this->profile_id,
            "account_type"      =>    $this->account_type,
            "date_created"      =>    $this->date_created,
            "date_modified"     =>    $this->date_modified,
            "status"            =>    $this->status,
            "status_1"          =>    $this->status_1,
            "email"             =>    $this->email,
            "email_activated"   =>    $this->email_activated,
            "is_active"         =>    $this->is_active
        );
    
        $insert_id = $this->db->insert($this->tblname, $insert_array);
    
        $this->id = $insert_id;
    }
    //
    public function update() {
        $update_array = array(
            //"unique_id"         =>    $this->unique_id,
            "username"          =>    $this->username,
            "password"          =>    $this->password,
            "profile_id"        =>    $this->profile_id,
            "account_type"      =>    $this->account_type,
            "date_created"      =>    $this->date_created,
            "date_modified"     =>    $this->date_modified,
            "status"            =>    $this->status,
            "status_1"          =>    $this->status_1,
            "email"             =>    $this->email,
            "email_activated"   =>    $this->email_activated,
            "is_active"         =>    $this->is_active
        );
    
        $condition_array = array("id" => $this->id);
    
        $this->db->update($this->tblname, $update_array, $condition_array);
    }

}

?>
